class Main extends React.Component {
    constructor(props) {
        super(props);
        this.state = {

        };
    }



    componentDidMount() {
        this.setState({ showloading: 'ON' })

        let UE = window.UE, that = this
        let ueditor = UE.getEditor('ueditor', {
            autoHeightEnabled: false,
            autoFloatEnabled: true
        });
        ueditor.addListener("ready", function () {
            that.setState({ ueditor }, () => {
                that.freshlist()
            });
        }, 2);
    }
    freshlist() {
        let that = this;
        Settingsgetdetail('useguide',res => {
            this.setState({ showloading: '' })
            if (res.issuccess == 1) {
                let { ueditor } = that.state
                ueditor.setContent(that.replaceraw(decodeURIComponent(res.data)))
            }
        })
    }

    replaceraw(content) {
        return content.replace('rgb(', 'rgb').replace(new RegExp('rgb', 'g'), "rgb(");
    }
    submit() {
        let { ueditor } = this.state, err = '', html = ueditor.getContent();
        if (!ueditor.hasContents()) err = '内容不能为空';
        if (err != '') {
            alert(err)
            return;
        }
        this.setState({ showloading: 'ON' })
        let value = this.replaceraw(encodeURIComponent(html))
        setuseguide(value, res => {
            this.setState({ showloading: '' })
            if (res.issuccess == 1) {
                alert('修改成功')
                // this.freshlist()
            }else{
                alert(res.msg)
            }
        })
        // window.location.href = "./addrole.html";
    }

    render() {
        let { listitem, name, path } = this.state;

        return (
            <div className="breadLinebox">
                <Loading hidden={this.state.showloading != 'ON'} />
                <div className='content_wrap panel-default content_wrap'>
                    <div className="breadLine">
                        <div className="img">
                            <img src='./src/lm_order1.png' />
                            使用指南
                        </div>
                    </div>
                    <div className="content">
                        <div>
                            <textarea id={'ueditor'} style={{ height: "70vh" }} ></textarea>
                        </div>

                        <div className="submitbox">
                            <button type="button" onClick={this.submit.bind(this)} className="submitbutton" style={{ cursor: 'pointer' }}>保存</button>
                        </div>
                    </div>
                </div>
            </div>


        )


    }
}





ReactDOM.render(
    <div>
        <TopLine />
        <div id='body'>
            <LeftMenu code='useguide' />
            <Main />
        </div>
    </div>
    // <Barrage/>
    , $('.container')[0]
)